<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="busyBook" label="作业" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="classHour" label="课时" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="classId" label="班次id" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="content" label="内容摘要" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="keyPoint" label="重点与难点" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="lessonDate"
        label="授课日期"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column prop="weeks" label="周次" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        lessonId: '',
      },
      tableData: [],
      pageObj: {},
    }
  },
  props: ['curLessonPlan'],
  mounted() {
    this.getList()
    this.$bus.$on('refreshLessonPlanList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshLessonPlanList')
  },
  methods: {
    async getList() {
      this.listQuery.lessonId = this.curLessonPlan.id
      let res = await this.$store.dispatch('queryEduLessonPlan', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    handleEdit(row) {
      this.$bus.$emit('showPlan', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    async delete(row) {
      await this.$store.dispatch('deleteEduLessonPlan', row)
      this.getList()
      this.successMsg('操作成功')
    },
  },
}
</script>
<style scoped lang="scss">
</style>